<script>
import { mapMutations, mapState } from "vuex";
export default {
  data() {
    return {
      timer: null,
    };
  },
  methods: {
    ...mapMutations(["changeWindowHeight", "changeUserInfo", "changeflag"]),

    getHeight() {
      const {
        windowHeight,
        statusBarHeight,
        titleBarHeight,
      } = uni.getSystemInfoSync();
      // #ifndef APP-PLUS || H5
      const height = windowHeight - titleBarHeight;
      // #endif
      // #ifdef APP-PLUS || H5
      const height = windowHeight - statusBarHeight - 44;
      // #endif
      this.changeWindowHeight(height);
    },
    getUserInfo() {
      try {
        let userInfo = uni.getStorageSync("userInfo");
        if (userInfo) {
          this.changeUserInfo(JSON.parse(userInfo));
        }
      } catch (e) {}
    },
    ddUpload() {
      const updateManager = dd.getUpdateManager();
      updateManager.onCheckForUpdate((res) => {
        this.changeflag(res.hasUpdate);
      });
      updateManager.onUpdateReady((ret) => {
        this.changeflag(ret);
        uni.showModal({
          title: "更新提示",
          content: "新版本已经准备好，是否重启应用？",
          showCancel: false,
          success: (res) => {
            if (res.confirm) {
              // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
              updateManager.applyUpdate();
            }
          },
        });
      });
      updateManager.onUpdateFailed((e) => {
        // 新版本下载失败
        this.changeflag(e);
      });
    },
  },
  computed: {
    ...mapState(["userInfo"]),
  },
  onLaunch: function() {
    this.getUserInfo();
    this.getHeight(); // 获取页面剩余区域高度
    // #ifdef MP-ALIPAY
    this.changeflag("App onLaunch");
    this.ddUpload();
    // #endif
  },
};
</script>

<style lang="scss">
// @import "uview-ui/index.scss";
page {
  background-color: #f8f8f8;
}
image {
  background-size: cover;
  background-position: center center;
}
/* #ifdef APP-PLUS || H5 */
/*每个页面公共css */
.padding_bar_height {
  padding-top: var(--status-bar-height);
}
.bar_height {
  position: fixed;
  top: 0;
  width: 100%;
  height: var(--status-bar-height);
  background-color: #f8f8f8;

  z-index: 9999;
}
/* #endif */
::v-deep .uni-navbar__content.uni-navbar--border {
  border: none !important;
}
::v-deep .uni-navbar__header-container.uni-navbar__content_view {
  font-size: 18px;
}
.padding_bar_height {
  padding-top: var(--status-bar-height);
}
::v-deep .uni-error-message-text {
  color: transparent !important;
}
::v-deep .uni-navbar {
  position: fixed;
  width: 100%;

  top: var(--status-bar-height);
  z-index: 999;
}
::v-deep .uni-list--border {
  margin-left: 0 !important;
  &::after {
    background-color: #f8f8f8 !important;
  }
}
::v-deep .uni-list-chat--first::after {
  background-color: transparent !important;
}
::v-deep .uni-list--border-top {
  background-color: transparent !important;
}
</style>
